package com.itheima.stock.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public Queue innerMarketQueue(){
        return new Queue("innerMarketQueue",true);
    }

    @Bean
    public Queue stockRtQueue(){
            return new Queue("stockRtQueue",true);
    }

    @Bean
    public Queue blockRtQueue(){
        return new Queue("blockRtQueue",true);
    }
    @Bean
    public Queue outerRtQueue(){
        return new Queue("outerMarketQueue",true);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("stockExchange",true,false);
    }


    @Bean
    public Binding bindingInnerMarketExchange(Queue innerMarketQueue,TopicExchange topicExchange){
        return BindingBuilder.bind(innerMarketQueue).to(topicExchange).with("inner.market");
    }

    @Bean
    public Binding bindingStockRtExchange(Queue stockRtQueue,TopicExchange topicExchange){
        return BindingBuilder.bind(stockRtQueue).to(topicExchange).with("stock.info");
    }

    @Bean
    public Binding bindingBlockRtExchange(Queue blockRtQueue,TopicExchange topicExchange){
        return BindingBuilder.bind(blockRtQueue).to(topicExchange).with("block.info");
    }
    @Bean
    public Binding bindingOuterRtExchange(Queue outerRtQueue,TopicExchange topicExchange){
        return BindingBuilder.bind(outerRtQueue).to(topicExchange).with("outer.market");
    }

}
